using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HermesPortalUI;
using HermesPortal.Core;  
public partial class Realms_Realm : PageBase 
{

    private int _realmID =0;
    private int RealmID
    {
        get
        {
            if (_realmID == 0)
            {
                if (Request.QueryString["RealmID"] != null)
                {
                    if (Int32.TryParse(Request.QueryString["RealmID"], out _realmID)) { }
                    else
                        Response.Redirect(Request.ApplicationPath + "/Default.aspx");
                }
            }
            return _realmID;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {

        RealmView1.SagaID = SagaID;
        RealmView1.RealmID = RealmID;
        RealmEdit1.SagaID = SagaID;
        RealmEdit1.RealmID = RealmID;

        if(IsInSagaRole( SagaRoles.sysAdmin ) || IsInSagaRole(SagaRoles.StoryGuide ))   
        {
            btnChangeView.Visible = true;
            if (RealmID == 0)
                SetRealmEditView(true);

        }
        else if (!IsPostBack)
        {
            SetRealmEditView(false);
        }

    }

    protected void OnClick_ChangeView(object source, EventArgs e)
    {
        SetRealmEditView(RealmView1.Visible);
    }

    protected void On_ClickSave(object source, EventArgs e)
    {
        RealmEdit1.SaveRealmChanges();
        SetRealmEditView(false);
    }

    protected void On_ClickCancel(object source, EventArgs e)
    {
        SetRealmEditView(false);
    }

    private void SetRealmEditView(bool isEditMode)
    {
        if (isEditMode)
        {
            btnChangeView.Text = "Change to Browser View";
            RealmEdit1.BindControls();  
        }
        else
        {
            btnChangeView.Text = "Change to Edit View";
             RealmView1.BindControls(); 
        }
            RealmEdit1.Visible = isEditMode;
            RealmView1.Visible = !isEditMode;
            btnUpdate.Visible = isEditMode;
            btnCancel.Visible = isEditMode;
           
       
    }
}
